<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

namespace Admin\Model;

use Think\Model;

class WriteModel extends Model {

        //根据id查询代写服务信息
        public function getWriteList($where=""){

            $join=array('cloud_user ON cloud_write.uid = cloud_user.id','cloud_write_type ON cloud_write.type_id = cloud_write_type.id','cloud_write_type_package ON cloud_write.package_id = cloud_write_type_package.id');
            $field = "cloud_write.*,cloud_user.username as userName,cloud_write_type.title as typeName,cloud_write_type_package.title as packageName";
            $res=getPages($this,$where,"","",$join,$field);
            
            return $res;
        }
         //根据id查询代写服务信息
        public function getWriteById($id){

            $join=array('cloud_user ON cloud_write.uid = cloud_user.id','cloud_write_type ON cloud_write.type_id = cloud_write_type.id','cloud_write_type_package ON cloud_write.package_id = cloud_write_type_package.id');
            $field = "cloud_write.*,cloud_user.username as userName,cloud_write_type.title as typeName,cloud_write_type_package.title as packageName";
            
            $res=$this->join($join)->field($field)->where("cloud_write.id=%s",$id)->find();

            //格式化内容
            $res["content"]=htmlspecialchars_decode($res["content"]);

            return $res;
        }

        //审核代写服务信息
        public function changeData($map){

            if(!$map){
                return false;
            }

            //拆分id
            $ids=explode(",",$map["ids"]);
            
            if($map["type"]=="apply"){
                $data["is_apply"]=$map["status"];
            }else{
                $data["is_ok"]=$map["status"];
            }

            $res=$this->where(array("id"=>array("in",$ids)))->save($data);
            
            if($res > 0){                
                return true;
            }else{
                return false;
            }

        }
    
   }


?>
